home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / shelsort.bas (.txt) < prev    next >
Encoding:
GW-BASIC  |  1984-04-24  |  1.2 KB  |  30 lines

  1. 50000  'This  is a short version of the Shell sort.
  2. 50010  'It is designed as a subroutine to be placed into your basic program.
  3. 50020  'The Shell Sort is an extremely fast Sort when you have a large number
  4. 50030  'of items to sort.  I benchmarked it against a "Bubble Sort" on an array
  5. 50040  'with 300 items 15 alpha-numeric characters long.  The Bubble sort took
  6. 50050  '25 min. and the Shell sort took 3 min!
  7. 50060  '
  8. 50070  '******************  S E T   U P  ************************************
  9. 50080  '
  10. 50090  '  1. You must DIMension the array A(J) before entering the sub-routine
  11. 50100  '  2. "LAST" must be assigned the value of the total number of items to
  12. 50110  '     be sorted.
  13. 50120  '
  14. 50130  '*************************  R E S U L T S  ***************************
  15. 50140  '
  16. 50150  'The Array A(J) will be sorted in ascending order at the end of the Sort.
  17. 50160  '
  18. 50170  '******  B A S I C   C O D E   F O R   S H E L L   S O R T    ********
  19. 50180  GAP=LAST\2
  20. 50190    WHILE GAP>0
  21. 50200      FOR I=GAP+1 TO LAST
  22. 50210        J=I-GAP
  23. 50220        WHILE J>0
  24. 50230          IF A(J)>A(J+GAP) THEN SWAP A(J),A(J+GAP):J=J-GAP ELSE J=0
  25. 50240        WEND
  26. 50250      NEXT
  27. 50260      GAP=GAP\2
  28. 50270    WEND
  29. 50280  RETURN  ' SORT  OF ARRAY A(J) COMPLETED
  30.